import xlrd,pymysql,requests
from feng_test_log.feng_test_logmethod import *
class MyMethod():
    def __init__(self):
        Log()
        self.logger = logging.getLogger()

        '''excelb表格读取'''
    def duQu_Excel(self,ExcelName,Sheet, a, b):
        PathCode=os.path.dirname(os.path.dirname(__file__))+'/feng_excel_case/'+ExcelName+'.xlsx'
        excel_Name = xlrd.open_workbook(PathCode)
        # 打开excel文件格式为xlsx有的是xls
        table = excel_Name.sheet_by_name(Sheet)
        cell_a1 = table.cell(a, b).value  # a代表行——从零开始   b代表列 从零开始
        self.logger.info(r'>>>获取excel表格内容：%s'%cell_a1)
        return cell_a1
    def selectSQL(self,sql):
        db=pymysql.connect(host="192.168.12.17", port=3116 ,user="mysql_yzbtest", password="jH7E6Y2zb3WX",db="yzb_app",charset ='utf8')
        cursor=db.cursor()
        #cursor.execute("select *  from  yzb_user WHERE NAME like '%s'"%('冯%'))
        cursor.execute(sql) #执行sql语句,并返回一个
        return cursor.fetchall()#取出的所有的值
    @staticmethod
    def longin():
        url = "http://api230.ezhibang.cn/auth/login/"

        # payload = "------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"phone\"\r\n\r\n13590283182\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW\r\nContent-Disposition: form-data; name=\"password\"\r\n\r\n123456\r\n------WebKitFormBoundary7MA4YWxkTrZu0gW--"
        headers = {
            # 'content-type': "multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW",
            'Content-Type': "application/x-www-form-urlencoded",
            'Cache-Control': "no-cache",
            'Postman-Token': "486a7752-41e1-480a-91d8-7b17a298ef36"
        }

        payload = {
            'phone': '13590283182',
            'password': '123456'
        }

        response = requests.request("POST", url, data=payload, headers=headers)

        print(response.text)
        a = response.json()
        print(a['data']['apikey'])
        b = a['data']['apikey']
        return b
